home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 1 / Precision Software Applications Silver Collection Volume One (PSM) (1993).iso / tutor / advtutr.exe / ADVENT4.DOC < prev    next >
Text File  |  1986-02-14  |  3KB  |  76 lines

  1.                    How to Write an Adventure part 4
  2.  
  3.                                                                             
  4.     The Command Parser
  5.     
  6.     Once you have displayed the status screen, you then must display a message 
  7. asking for the adventurer's input, and fetch his response. A simple input 
  8. statement works everytime: 
  9.     
  10.          1200 INPUT"WHAT WOULD YOU LIKE TO DO";ANSWER$
  11.          1210 IF ANSWER$="" THEN 1200
  12.                            
  13.     The above routine gets input and immediately checks to see if anything was 
  14. entered. If not, it goes back and tries again. DON'T OMIT THIS TRAP. The code 
  15. will spend lots of time doing nothing if you do.  
  16.     Once the input is fetched, it must be evaluated. The first test is to 
  17. determine if a one or two word command was entered. This is done by checking 
  18. for the presence of a space in the input string. The MID$ function allows us to 
  19. look at each character in a string one by one. If a space is found, then there 
  20. obviously must be two words in the input string, and we can break it into two 
  21. words... VERB$ and NOUN$. (Don't forget to clear the variables before you start 
  22. doing you check!!!!!): 
  23.          
  24.          1220 VERB$="":NOUN$=""
  25.          1230 FOR X=1 TO LEN(ANSWER$):IF MID$(ANSWER$,X,1)<>" " THEN 1250
  26.          1240 VERB$=LEFT$(ANSWER$,X-1):NOUN$=RIGHT$(ANSWER$,LEN(ANSWER$)-X):
  27.                X=LEN(ANSWER$)
  28.          1250 NEXT X:IF VERB$="" THEN 2000
  29.             
  30.     At line 2000 is the single command list, with which we will deal in a 
  31. moment.
  32.     Let us assume that two words have been found. We now must find out what 
  33. those words are, and determine if the program knows them. This is accomplished 
  34. as follows: 
  35.          
  36.          1260 V=0:N=0:FOR X=1 TO VERBS:IF VERB$(X)=VERB$ THEN V=X:
  37.                X=VERBS
  38.          1270 NEXT:IF V=0 THEN PRINT"I DON'T KNOW HOW TO ";VERB$;" SOMETHING":
  39.                GOTO 1200
  40.          1280 FOR X=1 TO NOUNS:IF NOUN$(X)=NOUN$ THEN N=X:X=NOUNS
  41.          1290 NEXT:IF N=0 THEN PRINT"I DON'T KNOW WHAT A ";NOUN$;" IS":
  42.                GOTO 1200
  43.     
  44.     And there we are. We first pass through the VERB$ list to see if the verb 
  45. we have entered is in the list. If it is not (V doesn't get assigned a value), 
  46. then we tell the adventurer that the verb is not understood. If the verb is 
  47. good, then we check the noun in the same way. If both pass the west then we go 
  48. the the VERB executive. This is simply an ON V GOTO statement that directs 
  49. program flow to the general area of the program that handles the verb 
  50. possibilities. It might look like this: 
  51.     
  52.          1300 ON V GOTO 3000,3100,3200,3300,3400,3500,3600,3700,3800
  53.     
  54.     If you need more ON V GOTO's than the line length allows, add more this 
  55. way:
  56.          1310 ON V-9 GOTO 3900,4000,4100,4200,4300,4400
  57.                        
  58.     We stated earlier that if the entered string was one word, we dealt with it 
  59. in a single word lookup list. It might look like this: 
  60.     
  61.          2000 IF ANSWER$="LOAD" THEN 10000
  62.          2010 IF ANSWER$="SAVE" THEN 11000
  63.          2020 IF ANSWER$="HELP" THEN 12000
  64.          2030 IF ANSWER$="INVENTORY" THEN 13000
  65.     
  66.     and so forth. In each case, the word triggers a branch to the routine to 
  67. give the desired result. We'll talk more about the routines to DO things in the 
  68. next chapter.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.